﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Course.aspx.cs" Inherits="OnLineExam.Web.mag.Course" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../jquery-easyui-1.2.5/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../jquery-easyui-1.2.5/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../jquery-easyui-1.2.5/jquery-1.7.1.min.js" type="text/javascript"></script> 
    <script src="../jquery-easyui-1.2.5/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../Scripts/jQuery.FillOptions.js" type="text/javascript"></script>
    <script src="../jquery-easyui-1.2.5/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script type="text/javascript"><!--
        $(function () {
            $("#selectDep").FillOptions('GetDepInfoHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>', { datatype: "json", textfield: "Name", valuefiled: "ID" });
            $("#selectCourse").FillOptions('GetCourseHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>', { datatype: "json", textfield: "CourseName", valuefiled: "CourseID" });
            <%if (User.IsInRole("教师")){ %>
                $("#dd table tr").eq(0).hide();
                        //$("#selectDep").attr("disabled", 'disabled'); //默认选中disabled
                        <%} %>
            $("#selectDep").change(function () {
            $("#selectCourse").empty();
             $("#selectCourse").FillOptions('GetCourseHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid='+$("#selectDep").val(), { datatype: "json", textfield: "CourseName", valuefiled: "CourseID" });
             });

            $('#tt').datagrid({

                idField: 'CourseID',
                url: 'Handler/CourseHandler.ashx?c=' + new Date().getMilliseconds() + '&type=getlist&depid=<%=Umodel.DepID %>', //?startIndex=0&endIndex=20  /''+ index +'/'
                singleSelect: true,
                columns: [[
                   { field: 'CourseID', title: '序号', width: 80 },
                  { field: 'CourseName', title: '科目', width: 250 },

                  { field: 'opt', title: '操作', width: 100, align: 'center',
                      formatter: function (value, rec, index) {
                          var e = '<a href="#" mce_href="#" onclick="edit(' + rec.CourseID + ')">编辑</a> ';
                          var d = '<a href="#" mce_href="#" onclick="del(' + index + ')">删除</a> ';
                          return e + d;
                      }
                  }
                ]],
                toolbar: [{
                    text: '增加', iconCls: 'icon-add', handler: function () {
                    add();
                    }
                } ,
                { text: '查找', iconCls: 'icon-search' }
                ],
                pagination: true, rownumbers: true
            });
        })


        function view(bh)  //转到查看页面
        {
            window.location.href = 'StuView.aspx?id=' + bh + '&page=stu';

        }
        function edit(bh)  //转到编辑页面
        { 
            $.ajax({
                type: "get",
                url: "Handler/CourseHandler.ashx?d=" + new Date().getMilliseconds() + "&type=edit&ID=" + bh,
                beforeSend: function (XMLHttpRequest) {
                    //ShowLoading();
                },
                success: function (data, textStatus) {
                    var obj = eval('(' + data.toString() + ')');

                    $("#selectDep").attr("value", obj.DepID);
                    
                      $("#hdType").val("editsave");
                     $("#hdID").val(bh); 
                    $("#txtCourseName").val(obj._coursename);
                    
                     
                  
                    $('#dd').dialog('open').dialog('setTitle', '编辑科目--' + obj._coursename);

                },
                complete: function (XMLHttpRequest, textStatus) {
                    //HideLoading();
                },
                error: function () {
                    //请求出错处理
                }
            });
           
            //window.location.href = 'StuEdit.aspx?id=' + bh;

        }
        function add(){
        $("#hdType").val("addsave");
            $("#hdID").val("");
                        $("#txtCourseName").val("");
                        
                        $("#selectDep").attr("value",'<%=Umodel.DepID %>');
                        $('#dd').dialog('open').dialog('setTitle', '添加科目');
        }

        function save() {

        $('#ff').form('submit', {  
    url: 'Handler/CourseHandler.ashx?d=' + new Date().getMilliseconds() + '&type='+$("#hdType").val(),
    onSubmit: function(){  
       return $(this).form('validate');
    },  
    success:function(data){  
        if (data > 0) {
                        $.messager.alert('操作结果', "执行成功，编号为：" + data, 'info');
                        $('#dd').dialog('close')
                    }
                    } 
});
$('#tt').datagrid('reload');

           // $("#ff").submit();
      }

        function del(index) {  //删除操作
            $.messager.confirm('确认', '确认删除?', function (row) {
                if (row) {
                    var selectedRow = $('#tt').datagrid('getSelected');  //获取选中行
                    $.ajax({
                        url: 'Handler/CourseHandler.ashx?type=del&id=' + selectedRow.CourseID,
                        //加了个type，作用是以后不管什么删除，都可以转到这个ashx中处理
                        success: function () { $.messager.alert('操作结果', "删除成功，编号为：" + selectedRow.CourseID, 'info');  }
                    });
                    $('#tt').datagrid('deleteRow', index);
                }
            })
}
// --></script>
</head>
<body>
    <table id="tt"></table>
    <div id="dd" class="easyui-dialog" style=" width:350px; padding:10px 20px" closed="true" buttons="#dd-buttons">  
     <form id="ff" method="post">
     <input id="hdType" name="hdType" type="hidden" />
     <input id="hdID" name="hdID" type="hidden" /> 
     <input id="hdDepID" name="hdDepID" type="hidden" value='<%=Umodel.DepID %>' />
    <table >
  <tr><td>部门：</td><td>
      <select id="selectDep" name="selectDep" class="easyui-validatebox" required="true">
          <option></option>
      </select></td></tr>
  <tr><td>科目：</td><td>
      <input id="txtCourseName" name="txtCourseName" type="text" />
      &nbsp;</td></tr>
  </table>
  </form>
</div>
<div id="dd-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>

		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dd').dialog('close')">取消</a>

	</div>

 
</body>
</html>